import * as event from "events";
import * as hx from "hbuilderx";

export default new class {
    private stack: string[] = [];
    private timer:any;
    private readonly TIMEOUT = 100;

    activate(context: any) {
        this.timer = setInterval(() => {
            this.read();
        }, this.TIMEOUT);
    }

    deactivate() {
        clearInterval(this.timer)
        this.stack = [];
    }

    notify(message: string) {
        this.stack.push(message);
    }

    readAll(){
        this.stack = [];
        hx.window.clearStatusBarMessage();
    }

    private read() {
        if (this.stack.length) {
            let message = this.stack.shift();
            hx.window.setStatusBarMessage(message);
        }
    }
}